Why should I use $[ EXPR ] instead of $(( EXPR ))?

Posted by qdii on Server Fault See other posts from Server Fault or by qdii
Published on 2013-06-30T12:11:05Z Indexed on 2013/06/30 16:22 UTC
Read the original article Hit count: 175

Filed under:
|

On the paragraph explaining arithmetic expansion, Bash's user guide uncovers 2 different ways of evaluating an expression, the first one uses $((?EXPRESSION?)) and the second one uses $[?EXPRESSION?]. The two ways seem pretty similar as the only difference I have found is:

$[?EXPRESSION?] will only calculate the result of EXPRESSION, and do no tests:

Yet, I am intrigued because the same document recommends using $[?EXPRESSION?] rather than $((?EXPRESSION?)).

Wherever possible, Bash users should try to use the syntax with square brackets:

Why would you want that if less tests are being done?

© Server Fault or respective owner

Related posts about bash

Related posts about variables